package com.itheima.maipiao.mai02;
/*
使用同步代码块解决线程安全问题

 */
public class Ticket implements Runnable {
    private int count=100;
    private static final Object obj= new Object();
    @Override
    public void run() {
        while(true){
            synchronized (this) {
                if(count<=0){
                    break;
                }else {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    count--;


                    System.out.println(Thread.currentThread().getName()+"正在卖票,还剩"+count);
                }
            }


        }
    }
}
